<?php

use think\migration\Migrator;
use app\model\PageSetting;

class AlterFixElmHuiYuan extends Migrator
{
    public function up()
    {
        $affectedNum = 0;
        PageSetting::query()
            ->where('setting_name', '饿了么会员')
            ->whereLike("ext_data", '%"jump_type": "1"}')
            ->select()->each(function (PageSetting $pageSetting) use (&$affectedNum){
                $new_ext_data = $ext_data = $pageSetting->ext_data;
                if (isset($ext_data['jump_type']) && !empty($ext_data['jump_type'])) {
                    $new_ext_data['jump_type'] = "5";
                    $pageSetting->ext_data = $new_ext_data;
                    $pageSetting->save();
                    $affectedNum++;
                }
            });
        echo '影响行数:'.$affectedNum;
    }
}
